package com.yuren.codecrushlearn.Q5100;

/**
 * Created with Intellij IDEA.
 * Description:
 * 二分查找递归实现
 * @author Sleepy Code Tom
 * @date 2025-04-16 00:38
 */
public class Q5182 {
    public int binarySearch(int[] arr, int n, int value) {
        return binarySearch_recur(arr, 0, n - 1, value);
    }

    private int binarySearch_recur(int[] arr, int low, int high, int value) {
        if (low > high) return -1;
        int mid = (low + high) / 2;
        if (arr[mid] == value) {
            return mid;
        } else if (arr[mid] > value) {
            return binarySearch_recur(arr, low, mid - 1, value);
        } else {
            return binarySearch_recur(arr, mid + 1, high, value);
        }
    }
}
